<?php
class Application_Model_Complaints extends Application_Model_DomainObject{
	
	protected $_id;
	
	protected $_userId;  //用户ID
	
	protected $_title;    //投诉标题
	
	protected $_content;    //投诉内容

        protected $_createTime;   //提交投诉时间
        
        protected $_isDelete;    //1代表删除

        protected $_reply;      //回复
        
        protected $_operator;      //操作人

        protected $_status;         //状态  0未处理  1已处理


        /***
         * 查询该用户所提交的投诉记录
         */
        public static function queryByUserid($userId){
            $where = array();
            $where['userId = '] = $userId;
            return self::getDao()->queryAll($where,'id desc');
        }
        
        public static function getMyByFilter($search,$pagesize,$start){
            return self::getDao()->queryPage($search->getSearchFileds(), " id desc ", $pagesize, $start);
        }
        
        /**
        * 根据userid，加载user对象
        * @author wuzw
        * @return type
        */
        public function getuserinfo() {
            if ($this->_userId) {
                return Application_Model_User::load($this->_userId);
            }
        }
        
         /**
         * 回复客户投诉 发站内信
         */
        public function sendMessage($title, $userId, $content){
            $messageItem = new Application_Model_Mail();
            $messageItem->Type = 2;
            $messageItem->Status = 0;
            $messageItem->UserId = $userId;
            $messageItem->DateCreated = date("Y-m-d H:i:s");            
            $messageItem->Title = "回复投诉：".$title;            
            $messageItem->Message = "尊敬的用户：您好！".$content;
            $messageItem->save();
        }
        
        /**
         * @return 会员投诉记录的个数
         */
        public static function getComplaintCount(){
            $where = array();
            $where['(status is null or status = 0) and (isDelete is null or isDelete = 0) and '] = 1;
            return self::getDao()->count($where);
        }
        
        
}